package agrep4me;

class LStates extends States {
	private long[] me;

	LStates() {
		me = new long[nlongs];
	}

	States empty() {
		return new LStates();
	}

	States copy() {
		LStates r = new LStates();

		for (int i = 0; i < nlongs; i++)
			r.me[i] = me[i];
		return r;
	}

	void assign(States from) {
		LStates lfrom = (LStates) from;
		for (int i = 0; i < nlongs; i++)
			me[i] = lfrom.me[i];
	}

	void clear() {
		for (int i = 0; i < nlongs; i++)
			me[i] = 0;
	}

	int getByte(int i) {
		int index = i / 8;
		int rem = i % 8;
		return (int) ((me[index] >>> (8 * rem)) & 255);

	}

	void add(int i) {
		int index = i / 64;
		int rem = i % 64;

		// System.err.println("add: " + i) ;
		me[index] |= (1L << rem);
	}

	boolean mem(int i) {
		int index = i / 64;
		int rem = i % 64;

		return (me[index] & (1L << rem)) != 0;
	}

	void or(States s) {
		LStates ls = (LStates) s;
		for (int i = 0; i < nlongs; i++)
			me[i] |= ls.me[i];
	}

	void and(States s) {
		LStates ls = (LStates) s;
		for (int i = 0; i < nlongs; i++)
			me[i] &= ls.me[i];
	}

	void shift() {
		int i = 0;
		long carry = 0;

		do {
			long t = me[i] >>> 63;
			me[i] <<= 1;
			me[i] |= carry;
			carry = t;
		} while (++i < nlongs);
	}

	boolean equals(States s) {
		LStates ls = (LStates) s;

		for (int i = 0; i < nlongs; i++) {
			if (me[i] != ls.me[i])
				return false;
		}
		return true;
	}
}
